<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\Api\TryController;
use App\Http\Controllers\Api\LoginController;
use App\Http\Controllers\Api\CategoryController;
use App\Http\Controllers\Api\CardController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

/*Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});*/


Route::namespace('Api')->group(function () {

    // 登录相关接口 频率限制
    Route::middleware(['throttle:' . config('api.rate_limits.sign')])->group(function () {
        // 测试
        Route::get('/try', [TryController::class,'try']);

        Route::post('/login', [LoginController::class,'login']);
        // 第三方登录 where限制了目前只支持qq和微信
        Route::get('/social-login/{type}', [LoginController::class,'socialLogin'])->where('type','qq|weixin');
        Route::get('/social-login-callback/{type}', [LoginController::class,'socialLoginCallBack'])->where('type','qq|weixin');
    });

    Route::middleware(['throttle:' . config('api.rate_limits.access'),'auth:api'])->group(function () {
        // 刷新token
        Route::get('/login-refresh', [LoginController::class,'refreshToken']);
        // 退出
        Route::get('/logout', [LoginController::class,'logout']);

        /**
         * 分类相关
         */
        Route::get('/category', [CategoryController::class, 'index']); // 新增
        Route::post('/category', [CategoryController::class, 'store']); // 新增
        Route::put('/category/{id}', [CategoryController::class, 'update']); // 编辑
        Route::put('/category/sort/{id}', [CategoryController::class, 'sort']); // 排序

        /**
         * 题目 卡片相关
         */
        Route::post('/card', [CardController::class, 'store']); // 新增
    });

});
